package com.dejavu.c4.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;


import javax.annotation.Resource;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

@Controller
public class DataSouceTest {

    @Resource
    DataSource dataSource;

    @GetMapping("/getDatasource")
    public String getDatasource(Model model) throws SQLException {
        //查看数据源
        System.out.println(dataSource.getClass());

        Connection connection = dataSource.getConnection();
        System.out.println(connection);
        model.addAttribute("datasource",dataSource.getClass());

        connection.close();

        return "test";
    }
}
